<?php

class WP_Info {

    var $infos = array();
    var $info_data = array();

    public function __construct() {
        LogUtil::info("class WP_Info", "__construct");
    }

    public function __destruct() {
        LogUtil::info("class WP_Info", "__destruct");
    }

    function WP_Info($code = '', $message = '', $data = '') {
        if ( empty($code) )
            return;

        $this->infos[$code][] = $message;

        if ( ! empty($data) )
            $this->info_data[$code] = $data;
    }

    function get_info_codes() {
        if ( empty($this->infos) )
            return array();

        return array_keys($this->infos);
    }

    function get_info_code() {
        $codes = $this->get_info_codes();

        if ( empty($codes) )
            return '';

        return $codes[0];
    }

    function get_info_messages($code = '') {
    // Return all messages if no code specified.
        if ( empty($code) ) {
            $all_messages = array();
            foreach ( (array) $this->infos as $code => $messages )
                $all_messages = array_merge($all_messages, $messages);

            return $all_messages;
        }

        if ( isset($this->infos[$code]) )
            return $this->infos[$code];
        else
            return array();
    }

    function get_info_message($code = '') {
        if ( empty($code) )
            $code = $this->get_info_code();
        $messages = $this->get_info_messages($code);
        if ( empty($messages) )
            return '';
        return $messages[0];
    }

    function get_info_data($code = '') {
        if ( empty($code) )
            $code = $this->get_info_code();

        if ( isset($this->info_data[$code]) )
            return $this->info_data[$code];
        return null;
    }

    function add($code, $message, $data = '') {
        $this->infos[$code][] = $message;
        if ( ! empty($data) )
            $this->info_data[$code] = $data;
    }

    function add_data($data, $code = '') {
        if ( empty($code) )
            $code = $this->get_info_code();

        $this->info_data[$code] = $data;
    }

}

?>